package ru.pb.game.objects.model;

import ru.pb.game.idfactory.IdFactory;
import ru.pb.game.objects.storage.IStoreableObject;
import ru.pb.game.objects.storage.ObjectsStorage;

public class GameObject implements IStoreableObject
{
	protected int _objectId;
	protected long _storedId;

	public GameObject(int objectId)
	{
		this(objectId, objectId > 0);
	}

	protected GameObject(int objectId, boolean putInStorage)
	{
		_objectId = objectId;
		_storedId = putInStorage ? ObjectsStorage.getInstance().put(this) : ObjectsStorage.getInstance().putDummy(this);
	}

	public void deleteMe(boolean release)
	{
		ObjectsStorage.getInstance().remove(_storedId);
		if(release)
			IdFactory.getInstance().releaseId(_objectId);
	}

	@Override
	public int getObjectId()
	{
		return _objectId;
	}

	@Override
	public long getStoredId()
	{
		return _storedId;
	}

	@Override
	public String getName()
	{
		return super.getClass().getSimpleName() + ":" + _objectId;
	}
}